"""
xpath模糊匹配
    关键字:contains()
    //标签名[contains(@属性名,"部分属性值")]
    例://span[contains(@class,"s-top")]

xpath多属性定位
    //标签名[@属性名1="属性值1" and @属性值2="属性值2"]
    例://input[@type = "hidden" and @name="tn"]
"""

# 1.导入需要的包
from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By

# 2.创建浏览器对象并打来浏览器
driver = webdriver.Chrome()
driver.maximize_window()  # 浏览器窗口最大化
driver.get("http://www.baidu.com")

# 元素定位+元素操作
# 使用xpath模糊匹配,定位百度首页设置按钮
driver.find_element(By.XPATH, '//span[contains(@class,"s-top")]').click()

input_el = driver.find_element(By.XPATH, '//input[@type = "hidden" and @name="tn"]')
print(input_el.get_attribute("outerHTML"))

# 关闭浏览器
sleep(5)
driver.quit()